package com.toman.Util;

import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.GetRequest;
import com.lzy.okhttputils.request.PostRequest;
import com.toman.Adpter.ItemListAdapter;
import com.toman.Enum.NetworkEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.ProductEntity;
import com.toman.MyApplication;
import com.toman.bean.ItemListBean;
import com.toman.bean.TemplateInfBean;
import com.toman.widget.callback.StringLoadingCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinPool;

import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by 邹苏隆 on 2018/9/17.
 * description：
 */
public class BaseNetUtil {

    public static void dep(Context context, List list, String token, String mCompanyId, ItemListAdapter adapter) {
        list.clear();
        OkHttpUtils
                .get(NewBaseUrl.department_list_get)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "部门列表: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString("departmentName"), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }


    public static void base(Context context, String title, String url, String name, List list, String token, String mCompanyId, ItemListAdapter adapter) {
        list.clear();
        OkHttpUtils
                .get(url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(name), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static void base(Context context, String title, String url, String name, List list, String token, String mCompanyId, ItemListAdapter adapter, String key) {
        list.clear();
        OkHttpUtils
                .get(url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(name), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static void baseProduct(Context context, String title, String url, String name, List list, String token, String mCompanyId, ItemListAdapter adapter) {
        list.clear();
        OkHttpUtils
                .get(url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(name), jsonArray.getJSONObject(i).getString("id"));

                                bean.setRemark(jsonArray.getJSONObject(i).getString("productMode"));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    //
    public static void base(Context context, NetworkEnum anEnum, List list, String token, String mCompanyId, ItemListAdapter adapter, String key) {
        list.clear();
        OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                if (anEnum==NetworkEnum.BELTLINE){
                                    bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                                    bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                                    bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                                }
                                else if(anEnum==NetworkEnum.SHIFT){

                                    bean.setRemark(jsonArray.getJSONObject(i).getString("isToday"));
                                }

                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static void base(Context context, NetworkEnum anEnum, List list,TextView textView, String token, String mCompanyId, ItemListAdapter adapter, String key) {
        list.clear();
        OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                if (anEnum==NetworkEnum.BELTLINE){
                                    bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                                    bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                                    bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                                }
                                else if(anEnum==NetworkEnum.SHIFT){

                                    bean.setRemark(jsonArray.getJSONObject(i).getString("isToday"));
                                }

                                list.add(bean);
                            }
                            if (list.size()<=0){
                                textView.setVisibility(View.VISIBLE);
                            }
                            else {
                                textView.setVisibility(View.GONE);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }


    public static void base(Context context, NetworkEnum anEnum, List list, String token, String mCompanyId, Map<String, String> map,ItemListAdapter adapter, String key) {
        list.clear();
        GetRequest params = OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1");
        for (Map.Entry<String, String> stringObjectEntry : map.entrySet()) {
            params.params(stringObjectEntry.getKey(), stringObjectEntry.getValue());
        }

        params .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                if (anEnum==NetworkEnum.BELTLINE){
                                    bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                                    bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                                    bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                                }
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }
    public static void base(TemplateInfBean templateInfBean, List list, ItemListAdapter adapter, TextView tv_nodata, String key) {
    Context context=MyApplication.getInstance();
    String token = (String) SPUtils.get(MyApplication.getInstance(), "token", "");
        list.clear();
    final NetworkEnum anEnum = templateInfBean.getNetwork();
    GetRequest params = OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", templateInfBean.getCompanyId())
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1");
        for (Map.Entry<String, String> stringObjectEntry : templateInfBean.getMap().entrySet()) {
            params.params(stringObjectEntry.getKey(), stringObjectEntry.getValue());
        }

        params .execute(new StringCallback() {
            @Override
            public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                Log.i("test", anEnum.title + ": " + result);

                JSONObject jsonObj = JSON.parseObject(result);
                int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                if (code == 0) {
                    JSONObject Jpage = jsonObj.getJSONObject("page");
                    JSONArray jsonArray;
                    if (Jpage==null){
                        if(anEnum==NetworkEnum.OPERATOR){
                            jsonArray = jsonObj.getJSONArray("users");
                        }
                    else {    jsonArray=jsonObj.getJSONArray("list");}
                    }

                   else  {  jsonArray = Jpage.getJSONArray("list");}
                    for (int i = 0; i < jsonArray.size(); i++) {
                        ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                        if (anEnum==NetworkEnum.BELTLINE){
                            bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                            bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                            bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                        }
                        if (anEnum==NetworkEnum.SHIFTANDTIME){
                            bean.setName(jsonArray.getJSONObject(i).getString(anEnum.name)+"("+jsonArray.getJSONObject(i).getString("startTime")+"-"+jsonArray.getJSONObject(i).getString("endTime")+")");
                        }
                        if (templateInfBean.getList_keys().size()!=0){
                            bean.getList_get().clear();
                            for (String s : templateInfBean.getList_keys()) {
                                bean.getList_get().add(jsonArray.getJSONObject(i).getString(s));
                            }
                        }
                        list.add(bean);
                    }
                    adapter.refreshData(list);
if (list.size()==0){
    tv_nodata.setVisibility(View.VISIBLE);
}else {
    tv_nodata.setVisibility(View.GONE);

}
                    adapter.notifyDataSetChanged();

                } else {
                    ToastUtil.makeText(context, jsonObj.getString("msg"));
                }

            }
        });
    }

    public static void base(Context context, NetworkEnum anEnum, List list, String token, String mCompanyId,String listName, ItemListAdapter adapter, String key) {
        list.clear();
        OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {

                            JSONArray jsonArray = jsonObj.getJSONArray(listName);
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }
    public static void base(Context context, NetworkEnum anEnum, List list, TextView view, String token, String mCompanyId, ItemListAdapter adapter, String key, Map<String,String> map) {
        list.clear();
        GetRequest params = OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1");
        if (map!=null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                params.params(entry.getKey(), entry.getValue());
            }
        }
               params .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                if (anEnum==NetworkEnum.BELTLINE){
                                    bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                                    bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                                    bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                                }
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();
                            if (list.size()==0){
                                view.setVisibility(View.VISIBLE);
                            }
                            else {
                                view.setVisibility(View.GONE);
                            }

                        } else {
                            view.setText( jsonObj.getString("msg"));
                            view.setVisibility(View.VISIBLE);

                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static void base(Context context, NetworkEnum anEnum, List list, TextView view, String token, String mCompanyId, ItemListAdapter adapter, String key, Map<String,String> map, ActionCallback callback) {
        list.clear();
        GetRequest params = OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", key)
                .params("limit", "1000")
                .params("page", "1");
        if (map!=null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                params.params(entry.getKey(), entry.getValue());
            }
        }
        params .execute(new StringCallback() {
            @Override
            public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                Log.i("test", anEnum.title + ": " + result);

                JSONObject jsonObj = JSON.parseObject(result);
                int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                if (code == 0) {
                    JSONObject Jpage = jsonObj.getJSONObject("page");
                    JSONArray jsonArray = Jpage.getJSONArray("list");
                    for (int i = 0; i < jsonArray.size(); i++) {
                        ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                        if (anEnum==NetworkEnum.BELTLINE){
                            bean.setRemark(jsonArray.getJSONObject(i).getString("terminalId"));
                            bean.setRemark2(jsonArray.getJSONObject(i).getString("terminalName"));
                            bean.setRemark3(jsonArray.getJSONObject(i).getString("terminalNum"));
                        }
                        list.add(bean);
                    }
                    adapter.refreshData(list);

                    adapter.notifyDataSetChanged();
                    if (list.size()==0){
                        view.setVisibility(View.VISIBLE);
                    }
                    else {
                        view.setVisibility(View.GONE);
                    }
                    callback.run();

                } else {
                    view.setText( jsonObj.getString("msg"));
                    view.setVisibility(View.VISIBLE);

                    ToastUtil.makeText(context, jsonObj.getString("msg"));
                }

            }
        });
    }


    public static void baseList(Context context, String title, String url, String name, String id, List list, String token, String mCompanyId, ItemListAdapter adapter) {
        list.clear();
        OkHttpUtils
                .get(url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(name), jsonArray.getJSONObject(i).getString(id));

                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static List<ItemListBean> base(Context context, String title, String url, String name, String token, String mCompanyId) {
        List<ItemListBean> list = new ArrayList<>();
        OkHttpUtils
                .get(url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(name), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
        return list;
    }

    public static List<ItemListBean> base(Context context, NetworkEnum anEnum, String mCompanyId) {
        String token= (String) SPUtils.get(context,"token","");
        List<ItemListBean> list = new ArrayList<>();
        OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                list.add(bean);
                            }
                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
        return list;
    }
    public static void base(Context context, NetworkEnum anEnum,List<ItemListBean> list, String mCompanyId,Map<String,String> map,ActionCallback actionCallback) {
        String token= (String) SPUtils.get(context,"token","");
//        枷锁
//        CountDownLatch downLatch = new CountDownLatch(1);
        GetRequest params = OkHttpUtils
                .get(anEnum.url)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1");
        if (map!=null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                params.params(entry.getKey(), entry.getValue());
            }
        }
                params.execute(new StringLoadingCallback(context) {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", anEnum.title + ": " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            if (jsonArray.size()==0){
                                ToastUtil.makeText(context, "暂无数据");

                            }
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString(anEnum.name), jsonArray.getJSONObject(i).getString(anEnum.id));
                                list.add(bean);
                                actionCallback.run();
                            }

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }


                    }
                });
//

    }


    public static void artline(Context context,List list, String token, String mCompanyId, ItemListAdapter adapter,String productName) {
        list.clear();
        OkHttpUtils
                .get(NewBaseUrl.workshop_operationartline_list)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .params("productName", productName)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "部门列表: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString("artlineName"), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public static List<ProductEntity> product(Context context, List list, String token, String mCompanyId, ItemListAdapter adapter) {
        List mList=new ArrayList<ProductEntity>();
        list.clear();
        OkHttpUtils
                .get(NewBaseUrl.workshop_product_list)
                .params("token", token)
                .params("companyId", mCompanyId)
                .params("key", "")
                .params("limit", "1000")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "产品列表: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);

                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString("productName"), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            List<ProductEntity> jsonArray1 = new ArrayList<>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), ProductEntity.class));
                            mList.addAll(jsonArray1);
                            adapter.refreshData(list);
                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.makeText(context, jsonObj.getString("msg"));

                        }

                    }
                });
        return mList;
    }

    public static void actionDialog(Context context, String url, String ids, String token, String title, ActionCallback actionCallback) {
        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化
        new AlertDialog.Builder(context)
                //对话框的标题
                .setTitle("确定要"+title+"？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", (dialog, whichButton) -> {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("ids", ids);
                    String str = JsonUtils.obj2JsonString(map);
                    OkHttpUtils
                            .post(url + ids)
                            .headers("token", token)
                            .postJson(str)
                            .execute(new StringCallback() {
                                @Override
                                public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                                    Log.i("test", title+":" + result);
                                    JSONObject jsonObj = JSON.parseObject(result);
                                    int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);


                                    if (code == 0) {
                                        ToastUtil.makeText(context, jsonObj.getString("msg"));
                                        actionCallback.run();
                                    } else {
                                        ToastUtil.makeText(context, jsonObj.getString("msg"));
                                    }
                                }
                            });
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();
    }

    public static void actionMapDialog(Context context, String url, Map<String, Object> map, String token, String title, ActionCallback actionCallback) {
        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化
        new AlertDialog.Builder(context)
                //对话框的标题
                .setTitle("确定要" + title + "？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", (dialog, whichButton) -> {
//                    String str = JsonUtils.obj2JsonString(map);
                    PostRequest postRequest = OkHttpUtils
                            .post(url)
                            .headers("token", token);
//                            .postJson(str)
                    for (Map.Entry<String, Object> stringObjectEntry : map.entrySet()) {
                        postRequest.params(stringObjectEntry.getKey(), String.valueOf(stringObjectEntry.getValue()));
                    }
                    postRequest.execute(new StringCallback() {
                        @Override
                        public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                            Log.i("test", title + ":" + result);
                            JSONObject jsonObj = JSON.parseObject(result);
                            int code = jsonObj.getInteger("code");ViewUtil.lagout(code,context);


                            if (code == 0) {
                                ToastUtil.makeText(context, jsonObj.getString("msg"));
                                actionCallback.run();
                            } else {
                                ToastUtil.makeText(context, jsonObj.getString("msg"));
                            }
                        }
                    });                    })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();
    }
}
